import java.util.ArrayList;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.*;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<car> carlist=new ArrayList<car>();
        carlist.add(Buyer.getCarInstanceByType("奔驰"));
        carlist.add(Buyer.getCarInstanceByType("宝马"));
        carlist.add(Buyer.getCarInstanceByType("法拉利"));
        carlist.add(Buyer.getCarInstanceByType("法拉利"));
        carlist.add(Buyer.getCarInstanceByType("法拉利"));

        for (car currentFruit : carlist){
            System.out.println(currentFruit.showName());
        }

        // 添加反射机制
        try {
            Class<?> carClass = Class.forName("BaomaEntity");
            car carInstance = (car) carClass.getDeclaredConstructor().newInstance();
            System.out.println( carInstance.showName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 读取XML文件
        try {
            File inputFile = new File("C:\\Users\\kzkzm\\Desktop\\软件设计\\automobile-factory-master\\untitled1\\src\\111.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(inputFile);
            doc.getDocumentElement().normalize();

            NodeList nodeList = doc.getElementsByTagName("car");
            for (int temp = 0; temp < nodeList.getLength(); temp++) {
                Node node = nodeList.item(temp);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    Element element = (Element) node;
                    String type = element.getElementsByTagName("type").item(0).getTextContent();
                    carlist.add(Buyer.getCarInstanceByType(type));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

// 其余类的定义保持不变


